package com.mdb.open.trade.validator;
/*
 * Copyright (C), 2017-2019 澳发科技(MDB)
 * FileName: CompanyinfoValidator.java
 * Author:   符楚
 * Date:     2019-10-12 09:59
 * History:
 * <author>          <time>          <version>          <desc>
 * 符楚               2019-10-12          V1.00             新建
 * -----------------------------------------------------------
 * 作者姓名           修改时间           版本号            描述
 */

import cn.hutool.core.util.StrUtil;
import com.mdb.bc.api.data.Result;
import com.mdb.bc.api.enums.ResultCode;
import com.mdb.bc.exception.MdbAssert;
import com.mdb.enums.PlatformRetCodeEnum;
import com.mdb.open.trade.feign.OutreachClient;
import com.mdb.open.trade.feign.dto.CompanyVerifyDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 企业信息校验<br>
 * <br>
 *
 * @author 符楚
 * @Date 2019-10-12 09:59
 */
@Component
public class CompanyinfoValidator {

    @Autowired
    OutreachClient outreachClient;

    /**
     * 企业信息校验
     *
     * @param companyName
     * @param regNo
     * @param frName
     */
    public void verify(String companyName, String regNo, String frName) {

        CompanyVerifyDto dto = new CompanyVerifyDto();
        dto.setRegNo(regNo);
        dto.setCompanyName(companyName);
        dto.setFrName(frName);

        Result<String> companyVerifyVoResult = outreachClient.companyVerify(dto);

        //查无数据
        if (companyVerifyVoResult.getRetCode().equals("201")) {
            MdbAssert.isTrue(false, PlatformRetCodeEnum.CUSTOMER_ASSERT_ERROR, "企业不存在");
        }
        //当前账户购买额度已用完, 或者异常
        MdbAssert.isTrue(companyVerifyVoResult.isSuccess(), ResultCode.FAIL, StrUtil.blankToDefault(companyVerifyVoResult.getData(), companyVerifyVoResult.getRetMsg()));

        String data = companyVerifyVoResult.getData();
        MdbAssert.isTrue("一致".equals(data), PlatformRetCodeEnum.CUSTOMER_ASSERT_ERROR, StrUtil.blankToDefault(companyVerifyVoResult.getData(), companyVerifyVoResult.getRetMsg()));
    }
}
